package gao.xioalei.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ConfigBean {
    @Bean
    public AntPathMatcher getAntPathMatcher(){
        return new AntPathMatcher();
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

//    @Bean
//    MultipartConfigElement multipartConfigElement() {
//        MultipartConfigFactory factory = new MultipartConfigFactory();
//        String location = System.getProperty("user.dir") + "/data/tmp";
//        File tmpFile = new File(location);
//        if (!tmpFile.exists()) {
//            tmpFile.mkdirs();
//        }
//        factory.setLocation(location);
//        return factory.createMultipartConfig();
//    }

//    @Bean
//    public MultipartResolver multipartResolver() {//如果不配置这个的话springboot就不支持put形式的form-data请求
//        return new StandardServletMultipartResolver() {
//            @Override
//            public boolean isMultipart(HttpServletRequest request) {
//                String method = request.getMethod().toLowerCase();
//                //By default, only POST is allowed. Since this is an 'update' we should accept PUT.
//                if (!Arrays.asList("put", "post").contains(method)) { return false; }
//                String contentType = request.getContentType();
//                return (contentType != null &&contentType.toLowerCase().startsWith("multipart/"));
//            }
//        };
//    }
}
